package lib

import (
	"time"
	//"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)



type IdsType struct {
	Ids    []int
}
//验证验证码
type FeedBackRespType	struct {
	RespCode				int
	Status		            string

}

//验证验证码
type CheckVerifyCodeType	struct {
	Tel				string
	VerifyCode		int

}

//验证验证码结果
type CheckVerifyCodeRespType	struct {
	RespCode				int
	Tel						string
	Status					string

}


//下载用户同步的数据
type DownloadType struct {
	UserID 		int64
	GroupID         int64
	Id			int
}
//同步遥控器数据
type UpdateCode struct {
	UserID 		int64
	GroupID         int64
}
//手机客户端的用返回格式
type ReturnCode struct {
	RespCode 		string
	UserPw			string
	GroupID         string
	Permission		byte					//权限位&0x01取出第一位，代表是否有直接更改密码的权限
}



type UpdateRemoteDataType struct {
	UserID		int64
	GroupID		int64
	LastTime	int64
}
type DelTelsType	struct {
	Tel            []string
}
type DelRemotesType struct {
	ObjectIDs		[]string
}
type TemperatureType struct {
	UserID		int64
	Mac			string
}
//用于获取表单中的bson数据
type BsonId struct {
	ObjetcId bson.ObjectId
}
////服务器响应
//type VerifyCodeType struct {
//	RespCode		int
//	VerifyCode				string
//}

type TelType struct {
	Tel					string		`valid:"Mobile"`
}

type UserSessionType struct {
	LastDate				time.Time
	Count					int
	VefifyCode				int
	IP						string
	Encryptionkey			string
}
type AdminSessionType struct {
	LastDate				time.Time
	Count					int
	VefifyCode				int
	IsLogin					bool
}
//用于网站进行ajax上传数据的返回值
type SiteResponeType struct {
	RespCode				int64
	Msg						string
	Data					interface {}
}

type AutoControlType struct {
	UserID				int64
	GroupID				int64
	Mac					string
	IsOpen			     bool
}

type TimeEventType struct {
	AccountMsg			string
	UserPwMsg			string
}
type LoginErrorMsg struct {
	AccountMsg			string
	UserPwMsg			string
}
//服务器响应
type ResponeType struct {
	RespCode		int
	Mac				string
	Status			int
}

type CodeTimeType   struct {
	TimeScale       int
	IRFRQ			int
	OpType			string
}

//服务器与终端通信的json格式
type REQ_RESP_Type struct {
	RespCode		int
	Mac				string
	Model			int
	DeviceType		int
	IP				string
	Port			int
	ProductName		string
	TimeScale       int
	IRFRQ			int
	OpType			string
	Mask			int

}
//设置开关的状态json格式
type P_SET_SWITCH struct {
	UserID			int64		`valid:"Required;Numeric"`
	GroupID			int			`valid:"Required;Numeric"`
	DeviceType		int			`valid:"Required;Numeric"`
	OpType			string		`valid:"Required;AlphaNumeric"`
	Mac				string		`valid:"Required;AlphaNumeric"`
	Mask			int			`valid:"Required;Numeric"`
}

//管理员注册json格式
type RegisterType struct {
	Tel					string		`valid:"Mobile"`
	UserPw				string		`valid:"Required;AlphaNumeric"`
	UserName			string		`valid:"Required;AlphaNumeric"`
	ProductID			string		`valid:"Required;AlphaNumeric"`
}

//手机用户注册json格式
type MobileRegisterType struct {
	Tel					string		`valid:"Mobile"`
	UserPw				string		`valid:"Required;AlphaNumeric"`
	ProductID			string		`valid:"Required;AlphaNumeric"`
}

//手机用户注册json格式
type MobileUpdateUserType struct {
	Tel					string
	UserPw				string
	VerifyCode			int
}

//管理员注册json格式
type AdminRegisterType struct {
	Tel					string		`valid:"Required;AlphaNumeric"`
	UserName			string		`valid:"Required;AlphaNumeric"`
	UserPw				string		`valid:"Required;AlphaNumeric"`
}

//用户注册json格式
type AdminRespType struct {
	RespCode			int			`valid:"Required;Numeric"`
	Msg					string		`valid:"Required;AlphaNumeric"`
}
//用户注册json格式
type Reg_Log_Type struct {
	RespCode			int			`valid:"Required;Numeric"`
	UserID				int64		`valid:"Required;Numeric"`
	GroupID				int64		`valid:"Required;Numeric"`
}
//登入json格式
type LoginType struct {
	Tel			string			`valid:"Mobile"`
	UserPw				string		`valid:"Required;AlphaNumeric"`
}
//手机与服务器数据同步json格式
type SynchroData struct {
	UserID				int64	`valid:"Required;Numeric"`
	GroupID				int64	`valid:"Required;Numeric"`
	OpType				int		`valid:"Required;Numeric"`
}

//type RespSynchroData struct {
//	RespCode			int		`valid:"Required;Numeric"`
//	Data				string		`valid:"Required;AlphaNumeric"`
//}
//手机为终端向服务器注册的json格式
type RegisterDeviceType struct {
	UserID					string		`valid:"Required;AlphaNumeric"`
	GroupID					string		`valid:"Required;AlphaNumeric"`
	DeviceType				int			`valid:"Required;Numeric"`
	ProductName				string		`valid:"Required;AlphaNumeric"`
	Mac						string		`valid:"Required;AlphaNumeric"`
}

type GetSwitchType struct {
	UserID					string		`valid:"Required;AlphaNumeric"`
	GroupID					string		`valid:"Required;AlphaNumeric"`
	Mac						string		`valid:"Required;AlphaNumeric"`
	Mask					int			`valid:"Required;Numeric"`
}

type HeartType struct {
	Mac				string		`valid:"Required;AlphaNumeric"`
	OpOpType		string		`valid:"Required;AlphaNumeric"`
	Model			int			`valid:"Required;Numeric"`
	RespCode		int			`valid:"Required;Numeric"`
	Mask			int			`valid:"Required;Numeric"`
}

type NewIPType struct {
	UserID					int64		`valid:"Required;Numeric"`
	GroupID					int64		`valid:"Required;Numeric"`
}


//服务器响应
type SetRemoteType struct {
	UserID			int64			`valid:"Required;Numeric"`
	GroupID			int64			`valid:"Required;Numeric"`
	//CodeTime		CodeTimeType
	DeviceType		int				`valid:"Required;Numeric"`
	TimeScale       int				`valid:"Required;Numeric"`
	IRFRQ			int				`valid:"Required;Numeric"`
	OpType			string		`valid:"Required;AlphaNumeric"`
	Mac				string		`valid:"Required;AlphaNumeric"`
	Mask			int			`valid:"Required;Numeric"`
}




//用于解析短信服务中对方的返回数据
type TelXML struct {
	Code  		  	int `xml:"code"`
	Msg       	  	string `xml:"msg"`
	Smsid   		string `xml:"smsid"`

}

/*************************wifi终端设备*************************/
//用于Model位
const (

	SET_DEVICE_STATUS		= 	iota				   //改变开关的状态
	CHANGE_IP						   //通知设备更改IP
	SET_REMOTE_STATUS                  //控制红外遥控器
	DEVICE_CONN							//设备发起websocket连接到服务器，服务器也以些响应终端
	DEVICE_HEART							//设备发起心跳，连接到服务器，防止自己掉线，服务器也以些响应终端
	CHECK_DEVICE_STATUS					//查询设置的状态，只能用于开关
	FIND_ROUTER_DEVICE                 //查找路由器下存在的设备
	CHECK_ROUTER_DEVICE					//查看设备是否在局域网下
	REMOTE_LEARN						//设备红外设备进入学习状态
	GET_REMOTE_DATA						//当设备处于遥控器学习状态下，向设备获取从遥控解码来的数据
	SET_WIFI						//给终端设备设置wifi
	GET_TEMPERATURE						//获取设备的温度
	SET_GRADUAL							//设置开关的渐亮渐灭
	CHECK_GRADUAL							//设置开关的渐亮渐灭
)

//用于OpType位
const (
	SWITCH_ON     = "0"
	SWITCH_OFF    = "1"       //设备发起websocket连接到服务器
	OpType_INVALID = "0"
)
/***********************************************************/



//RespCode
const (
	SUCCESS     		= 0       //操作成功
	OFFLONE    			= 1       //设备不在线
	PARA_ERROR  		= 2       //参数错误
	PARA_JSON_ERROR  	= 3       //参数JSON序列化错误
	OPERATION_ERROR		= 4		//系统操作失败
	OPERATION_CHECK		= 5		//数据转为重查
	INVALID_NAME        = 6     //帐号出错
	INVALID_PW        	= 7     //密码出错
	EXIST_NAME       	= 8     //注册时，该手机号已经被注册
	RES_REGISTER		= 9     //设备未向服务器发起注册，或者设备以掉线，设备重连
	TEL_NULL			= 10    //电话号码为空
	MAX_MSG				= 11    	//该手机号已经超过最大的验证次数
	NOT_TEL				= 12		//效的手机号
	VERIFY_CODE_ERR				= 13		//验证码错误
	NEED_LOGIN			= 14
	NO_NEW_VERSION			= 15
	INVALID     		= 0         //该位无效
	INVALIDS    		= "0"


)

//用于网站的RespCode
const (
	SITE_SUCCESS     		= 200       //操作成功
	SITE_PARA_ERROR  		= 201       //参数错误
	SITE_WRITE_SQL_ERROR  	= 202       //参数JSON序列化错误
	SITE_VERIFY_CODE  	   = 203       //验证码错误
	SITE_PERMISSION_ERR  	   = 204       //验证码错误
	SITE_DELETE_ERR			= 205
	SITE_OPERATION_ERROR	= 206


)


//Resp  MSG
const (
	TEL_NULL_MSG 			= "手机号为空"
	MAX_MSG_MSG 			= "该手机号已经超过最大的验证次数"
	SUCCESS_MSG				= "短信已发送"
)
//device
const(
	DEVICE_SWITCH       = 0
	DEVICE_REMOTE       = 1
)
//var INVALID_CODE_TIME   = CodeTimeType{0,0,[2]int32{0,0},[2]int32{0,0}}
const(
	ONEDAY2SEC			= 86400
	MAX_THRESHOLD		= 2^64
	MAC_PARTICLE_SIZE	= 1440
	DEFAULT_PARTICLE_SIZE	= 10
	DEFAULT_THRESHOLD_SIZE	= 10
	DEFAULT_MASHINE_LEARN	= false
	DEFAULT_MAX_MSG	    int			= 5
	CLIENT_VALID_SECOND		= 600
)

//由于beego不支持没有cookit的session，所以在手机端无法使用，只能自己实现内存session
var SelfSession map[interface {}]interface {}
